// vue-echarts
import ECharts from 'vue-echarts'
import { use } from "echarts/core"
import {
    CanvasRenderer,
  } from 'echarts/renderers'
  import {
    BarChart,PieChart,MapChart,EffectScatterChart,LineChart,ScatterChart,
  } from 'echarts/charts'
  import {
    GridComponent,
    TitleComponent,
    TooltipComponent,
    LegendComponent,
    DatasetComponent,
    VisualMapComponent,
    GeoComponent,
    MarkPointComponent
  } from 'echarts/components'
  // 新增：从 echarts-gl 导入 WebGLRenderer
  import 'echarts-gl'
  use([
    CanvasRenderer,
    BarChart,PieChart,MapChart,EffectScatterChart,LineChart,ScatterChart,
    GridComponent,
    LegendComponent,
    TooltipComponent,
    TitleComponent,
    DatasetComponent,
    VisualMapComponent,
    GeoComponent,
    MarkPointComponent
  ])

  export const registerEcharts= (app:any)=>{
    // 注册全局组件，并设置默认属性
    app.component('v-chart', ECharts, {
      // 默认属性配置
      inheritAttrs: true
    })
    
    // 设置全局默认配置
    app.config.globalProperties.$echartsDefaultOptions = {
      // 确保图表自适应容器大小
      renderer: 'canvas',
      useDirtyRect: false
    }
  }
  
  // 导出默认的图表配置
  export const defaultChartConfig = {
    // 确保图表能够响应容器大小变化
    animation: true,
    animationDuration: 1000,
    // 自适应配置
    responsive: true,
    maintainAspectRatio: false
  }